package com.deer.wms.kuaidiniao.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.deer.wms.kuaidiniao.model.WlgzRequestData;
import com.deer.wms.kuaidiniao.utils.Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

import static com.deer.wms.kuaidiniao.constant.KuaidiniaoConstant.EBusinessID;
import static com.deer.wms.kuaidiniao.constant.KuaidiniaoConstant.AppKey;
import static com.deer.wms.kuaidiniao.constant.KuaidiniaoConstant.WlgzReqURL;

@Service
@Transactional
public class WlgzApi {

    public String orderTraceSubByRequestData(WlgzRequestData requestData) throws Exception {
        String jsonData = "";
        jsonData = JSONArray.toJSONString(requestData);
        return orderTracesSubByJson(jsonData);
    }
    /**
     * Json方式  物流信息订阅
     * @throws Exception
     */
    public String orderTracesSubByJson(String requestData) throws Exception{

        Map<String, String> params = new HashMap<String, String>();
        params.put("RequestData", Utils.urlEncoder(requestData, "UTF-8"));
        params.put("EBusinessID", EBusinessID);
        params.put("RequestType", "1008");
        String dataSign=Utils.encrypt(requestData, AppKey, "UTF-8");
        params.put("DataSign", Utils.urlEncoder(dataSign, "UTF-8"));
        params.put("DataType", "2");

        String result=Utils.sendPost(WlgzReqURL, params);
        return result;
    }
}